package com.yourname.action;

import com.yourname.entity.Student;
import com.yourname.entity.Teacher;
import com.yourname.store.DataStore;

import java.util.Scanner;

public class RegistAction {
    /**
     * 学生注册功能
     */
    public static void registerStudent(){
        System.out.println("""
                请输入学号、姓名、年龄、密码，中间用短横杠-分割
                """);
        Scanner scanner=new Scanner(System.in);
        String info = scanner.next();
        String[] split = info.split("-");
        Student student=new Student();
        student.setId(split[0]);
        student.setName(split[1]);
        student.setAge(Integer.parseInt(split[2]));
        student.setPassword(split[3]);
        DataStore.addStudent(student);
        DataStore.saveData();
    }

    /**
     * 教师注册功能
     */
    public static void registerTeacher(){
        System.out.println("""
                请输入教职工号、姓名、年龄、密码，中间用短横杠-分割
                """);
        Scanner scanner=new Scanner(System.in);
        String info = scanner.next();
        String[] split = info.split("-");
        Teacher teacher=new Teacher();
        teacher.setId(split[0]);
        teacher.setName(split[1]);
        teacher.setAge(Integer.parseInt(split[2]));
        teacher.setPassword(split[3]);
        DataStore.addTeacher(teacher);
        DataStore.saveData();
    }
}
